package com.wanpinghui.wphlibrary.model.oauth;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.wanpinghui.wphlibrary.WPHLibrary;
import com.wanpinghui.wphlibrary.model.oauth.bean.UserBean;
import com.yunshl.yunshllibrary.storage.ShareDataManager;
import com.yunshl.yunshllibrary.storage.SharedPreferencesKey;
import com.yunshl.yunshllibrary.utils.TextUtil;

import retrofit.ToKenUtil;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2017/11/22
 ***/

public class UserInfoUtil {
    public static void deleteUserInfo() {
        ShareDataManager.getInstance().delete(WPHLibrary.getLibrary().getContext(), SharedPreferencesKey.KEY_USER_INFO);
        ToKenUtil.deleteToken();
    }

    public static void saveUserInfo(UserBean userInfoBean) {
        if (userInfoBean == null)return;
        ShareDataManager.getInstance().save(WPHLibrary.getLibrary().getContext(), SharedPreferencesKey.KEY_USER_INFO, new Gson().toJson(userInfoBean));
    }

    public static UserBean getUserInfo() {
        String userInfoStr = ShareDataManager.getInstance().getPara(SharedPreferencesKey.KEY_USER_INFO);
        if (TextUtil.isNotEmpty(userInfoStr)) {
            return new Gson().fromJson(userInfoStr, new TypeToken<UserBean>(){}.getType());
        }
        return null;
    }
}
